/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nuce.entity;

import dataaccess.DataAccess;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author LINHNC
 */
public class Question {

    private int Id;
    private String content;
    private String answer1;
    private String answer2;
    private String answer3;
    private String answer4;
    private int level;

    public Question(){
        this.Id = 0; this.content= null;
        this.answer1 = null; this.answer2 = null; this.answer3 = null; this.answer4 = null;
        this.level =1;
    }
    public Question(int Id, String content, String answer1, String answer2, String answer3, String answer4, int level) {
        this.Id = Id;
        this.content = content;
        this.answer1 = answer1;
        this.answer2 = answer2;
        this.answer3 = answer3;
        this.answer4 = answer4;
        this.level = level;
    }

    public int getId() {
        return Id;
    }

    public void setId(int Id) {
        this.Id = Id;
    }

    public String getAnswer1() {
        return answer1;
    }

    public void setAnswer1(String answer1) {
        this.answer1 = answer1;
    }

    public String getAnswer2() {
        return answer2;
    }

    public void setAnswer2(String answer2) {
        this.answer2 = answer2;
    }

    public String getAnswer3() {
        return answer3;
    }

    public void setAnswer3(String answer3) {
        this.answer3 = answer3;
    }

    public String getAnswer4() {
        return answer4;
    }

    public void setAnswer4(String answer4) {
        this.answer4 = answer4;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }
    public Vector getquestion() throws SQLException
    {
        Vector v=new Vector();
        try
        {
            ResultSet rs=DataAccess.executeQuery("getquestion");
            while(rs.next())
            {
                Question qs=new Question();
                qs.setId(rs.getInt(1));
                qs.setContent(rs.getString(2));
                qs.setAnswer1(rs.getString(3));
                qs.setAnswer2(rs.getString(4));
                qs.setAnswer3(rs.getString(5));
                qs.setAnswer4(rs.getString(6));
                qs.setLevel(rs.getInt(7));
                v.add(qs);
            }
        }
        catch(SQLException sql)
        {
            System.out.println(sql.getMessage());
        }
        return v;
    }
    public Vector BinQuestion(String s) throws SQLException
    {
        Vector v=new Vector();
        Vector param=new Vector();
        param.add(s);
        
            try
            {
            
            ResultSet rs=DataAccess.executeQuery("Question_SelectByContent", param);

            while(rs.next()){
                Question qs=new Question();
                qs.setId(rs.getInt(1));
                qs.setContent(rs.getString(2));
                qs.setAnswer1(rs.getString(3));
                qs.setAnswer2(rs.getString(4));
                qs.setAnswer3(rs.getString(5));
                qs.setAnswer4(rs.getString(6));
                qs.setLevel(rs.getInt(7));
                v.add(qs);
                }
            }
            catch(SQLException sql){
                System.out.println(sql.getMessage());
            }
        
        return v;
        }
    public int insertQuestion(Question qs) throws SQLException
    {
        int i=0;
        try{
            Vector v=new Vector();
            v.add(qs.getContent());
            v.add(qs.getAnswer1());
            v.add(qs.getAnswer2());
            v.add(qs.getAnswer3());
            v.add(qs.getAnswer4());
            v.add(qs.getLevel());
            i=DataAccess.executeUpdate("Question_Insert", v);
        }
        catch(SQLException sql){
            System.out.println(sql.getMessage());
        }
        return i;
    }
    public int EditQuestion(Question qs) throws SQLException
    {
        int i=0;
        try{
            Vector v=new Vector();
            v.add(qs.getContent());
            v.add(qs.getAnswer1());
            v.add(qs.getAnswer2());
            v.add(qs.getAnswer3());
            v.add(qs.getAnswer4());
            v.add(qs.getLevel());
            i=DataAccess.executeUpdate("Question_Update", v);
        }
        catch(SQLException sql){
            System.out.println(sql.getMessage());
        }
        return i;
    }
    public int DeleteQuestion(String qs) throws SQLException
    {
        int i=0;
        try{
            Vector v=new Vector();
            v.add(qs);
            i=DataAccess.executeUpdate("Question_deleteById", v);
        }
        catch(SQLException sql)
        {
            System.out.println(sql.getMessage());
        }
        return i;
    }
}
